package qimao.com.edu.entity;

import java.util.List;

public class Page<t> {
	private List<t> data;//查到的数据（查）
	private int pageNum;//当前页号
	private int pageSize;//页大小
	private int totalRows;//总条数（查）
	private int totalPages;//总页数
	private boolean hasPrev;//上页
	private boolean hasNext;//下页
	
	private int[] nagigatorNum;//页码条
	
	public List<t> getData() {
		return data;
	}
	public void setData(List<t> data) {
		this.data = data;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public boolean isHasPrev() {
		return hasPrev;
	}
	public void setHasPrev(boolean hasPrev) {
		this.hasPrev = hasPrev;
	}
	public boolean isHasNext() {
		return hasNext;
	}
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
	public int[] getNagigatorNum() {
		return nagigatorNum;
	}
	public void setNagigatorNum(int[] nagigatorNum) {
		this.nagigatorNum = nagigatorNum;
	}
	public Page() {
		super();
	}
	public Page(List<t> data, int pageNum, int pageSize, int totalRows) {
		super();
		this.data = data;
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalRows = totalRows;
		
		//总页数
		totalPages = totalRows % pageSize == 0?totalRows / pageSize : (totalRows / pageSize)+1;
		hasPrev = true;
		hasNext = true;
		// 判断是否存在下一页 或者 上一页
		if(pageNum <= 1) {
			hasPrev = false;
		}
		if(pageNum >= totalPages ) {
			hasNext = false;
		}
		if(totalPages > 10) {
			nagigatorNum = new int[10];
		}else {
			nagigatorNum = new int[totalPages];
		}
		//总页数小于10 或者 当前页小于5  都显示1-totalPages
		if(pageNum <= 5 || totalPages < 10) {
			for (int i = 0; i < nagigatorNum.length; i++) {
				nagigatorNum[i] = i+1;
			}
			//最后10页
		}else if(totalPages-pageNum <= 10){
			for (int i = 0,k = totalPages-10 ; i < nagigatorNum.length; i++,k++) {
				nagigatorNum[i] = k+1;
			}
		}else {
			for (int i = 0,k = pageNum-4; i < nagigatorNum.length; i++,k++) {
				nagigatorNum[i] = k+1;
			}
		}
	}
	
}
